home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00a.txt / 000160_icon-group-sender _Tue Jun 27 16:55:20 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA21064
  4.     for icon-group-addresses; Tue, 27 Jun 2000 16:55:06 -0700 (MST)
  5. Message-Id: <200006272355.QAA21064@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 27 Jun 2000 13:08:59 -0700 (MST)
  7. From: Gregg Townsend <gmt@baskerville.CS.Arizona.EDU>
  8. To: Steve_Graham@labcorp.com, icon-group@optima.CS.Arizona.EDU
  9. Subject: Re: Permutations/Combinations
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12.  
  13.     From: "Steve Graham" <Steve_Graham@labcorp.com>
  14.     
  15.     Although I do not know how to utilize Icon's built-in features to generate
  16.     all possible combinations/permutations (which one is it?) where the letters
  17.     appear once and only once, I do believe that, given the generated list, I
  18.     will recognize the valid words.  And I'm sure that Icon can EASILY produce
  19.     the list, whether the algorthim utilizes reversible assignment or not.
  20.     Can someone show me how?
  21.     
  22. The Icon program library contains a nice little permutation generator
  23. (in the procs/strings.icn file):
  24.  
  25.     procedure permute(s)
  26.        local i
  27.        if *s = 0 then return ""
  28.           suspend s[i := 1 to *s] || permute(s[1:i] || s[i+1:0])
  29.     end
  30.  
  31. So to generate all 720 permutations you'd just do this:
  32.  
  33.     procedure main()
  34.        every write(permute("abelmr"))
  35.     end
  36.  
  37.    ---------------------------------------------------------------------------
  38.    Gregg Townsend         Staff Scientist      The University of Arizona
  39.    gmt@cs.arizona.edu     Computer Science     Tucson, Arizona, USA
  40.